package com.english.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.english.entity.ClassHoursLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 班级课时变动日志Mapper
 *
 * @author wlq
 * @since 2025-08-06
 */
@Mapper
public interface ClassHoursLogMapper extends BaseMapper<ClassHoursLog> {

    /**
     * 获取学生的课时变动日志（带详细信息）
     */
    @Select("SELECT chl.*, u.name as student_name, cc.class_name, ua.name as admin_name " +
            "FROM class_hours_log chl " +
            "LEFT JOIN user u ON chl.student_id = u.id " +
            "LEFT JOIN course_class cc ON chl.class_id = cc.id " +
            "LEFT JOIN user ua ON chl.admin_id = ua.id " +
            "WHERE chl.student_id = #{studentId} " +
            "ORDER BY chl.create_time DESC")
    List<ClassHoursLog> selectByStudentIdWithDetails(@Param("studentId") Long studentId);

    /**
     * 获取班级的课时变动日志
     */
    @Select("SELECT chl.*, u.name as student_name, cc.class_name, ua.name as admin_name " +
            "FROM class_hours_log chl " +
            "LEFT JOIN user u ON chl.student_id = u.id " +
            "LEFT JOIN course_class cc ON chl.class_id = cc.id " +
            "LEFT JOIN user ua ON chl.admin_id = ua.id " +
            "WHERE chl.class_id = #{classId} " +
            "ORDER BY chl.create_time DESC")
    List<ClassHoursLog> selectByClassIdWithDetails(@Param("classId") Long classId);
} 